﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Program05
{
    //成绩管理类（管理类不允许修改只允许引用）
    public class GradeManage
    {
        //只读
        public Student2 Stu { get; }
        public Course1 C1 { get; }
        public Course2 C2 { get; }

        //利用泛型解决多个相同类的管理
        public List<Course1> course1s { get; }


        public int Sum { get; }

        public GradeManage()
        {

        }

        //只初始化学生信息的构造方法
        public GradeManage(string stuNo,string stuName,int age)
        {
            Stu = new Student2()
            {
                No = stuNo,
                Name = stuName,
                Age = age
            };
        }
        //带有课程的构造函数
        public GradeManage(string stuNo, string stuName, int age,string cName1,int cPeriod1,int cCredit1,int cScore1)
        {
            Stu = new Student2()
            {
                No = stuNo,
                Name = stuName,
                Age = age
            };

            C1 = new Course1()
            {
                Name = cName1,
                Period = cPeriod1,
                Creidt=cCredit1,
                Score=cScore1
            };
        }



        //带课程的构造方法
        public GradeManage(string stuNo, string stuName, int age,
            string cName1, int cPeriod1, int cCredit1, int cScore1,
            string cName2, int cPeriod2, int cCredit2, int cScore2)
        {
            Stu = new Student2()
            {
                No = stuNo,
                Name = stuName,
                Age = age
            };

            C1 = new Course1()
            {
                Name = cName1,
                Period = cPeriod1,
                Creidt = cCredit1,
                Score = cScore1
            };

            C2 = new Course2()
            {
                Name = cName2,
                Period = cPeriod2,
                Creidt = cCredit2,
                Score = cScore2
            };

            Sum = C1.Score + C2.Score;
        }
        public GradeManage(string stuNo, string stuName, int age,params Course1[] course1s)
        {
            Stu = new Student2()
            {
                No = stuNo,
                Name = stuName,
                Age = age
            };
            this.course1s = new List<Course1>();
            foreach (var item in course1s)
            {
                this.course1s.Add(item);
            }
        }


        public float ScoreAvg()//计算平均分
        {
            float i = 0;
            foreach (var item in course1s)
            {
                i += item.Score;
            }
            return i / course1s.Count;
        }
        public float ScoreSum()//总分
        {
            return ScoreAvg() * course1s.Count;
        }





        //打印方法
        //采用实例多个对象的方法管理的Tostring重写
        //public void Print() => Console.WriteLine($"{Stu}{C1}{C2} 总分：{Sum}");

        //采用泛型方法管理的Tostring重写
        public void PrintMessage()//输出学生信息
        {
            Console.Write(Stu + " ");

            if (course1s != null)
            {
                foreach (var item in course1s)
                {
                    Console.Write(item + " ");
                }
            }
            Console.WriteLine();
        }
    }
}
